{% extends "shared/layout.volt" %}
{% block content %}
    <h1 class="page-header">编辑角色</h1>
    <div class="form-box" style="width: 550px;margin-top: 20px;">
        <form class="form-horizontal" method="post" id="formResourceEdit">
            <input type="hidden" name="role_id" id="role_id" value="{{ Model.role_id }}">
            <div class="form-title-box">
                <h3 class="view-title">基础信息</h3>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">角色名称</label>
                <div class="col-sm-9">
                    <input type="text" maxlength="200" name="role_name" placeholder="资源名称" value="{{ Model.role_name }}" class="form-control input-sm">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">角色状态</label>
                <div class="col-sm-9">
                    <div class="radio_box">
                        <label for="role_state1" class="enable{{ Model.role_state == 1 ? ' selected' : '' }}">禁用</label>
                        <label for="role_state2" class="disable{{ Model.role_state == 0 ? ' selected' : '' }}">启用</label>
                        <input type="radio" value="1" name="role_state" id="role_state1"{{ Model.role_state == 1 ? ' checked="checked"' : '' }}>
                        <input type="radio" value="0" name="role_state" id="role_state2"{{ Model.role_state == 0 ? ' checked="checked"' : '' }}>
                    </div>
                    <p class="sub-text">角色禁用后，拥有该角色的用户将没有任何权限</p>
                </div>
            </div>
            <div class="form-title-box">
                <h3 class="view-title">资源列表</h3>
            </div>
            {% for resource in ResourceList %}
                <div class="form-small-title-box">
                    <h3 class="view-title">{{ resource['name'] is not empty ? resource['name'] : '其他' }}</h3>
                </div>
                <div class="form-group" style="padding: 0px 50px;">
                {% for action in resource['actions']  %}
                    <label class="ant-checkbox-wrapper">
                            <span class="ant-checkbox<?php  if (empty($Model->resource_list) === false && in_array($action->resource_id,$Model->resource_list)): ?> ant-checkbox-checked<?php endif ?>">
                                <span class="ant-checkbox-inner"></span>
                                <input type="checkbox" name="resource_id[]" class="ant-checkbox-input" value="{{ action.resource_id }}" <?php  if (empty($Model->resource_list) === false && in_array($action->resource_id,$Model->resource_list)): ?> checked<?php endif ?>>
                                {{ action.display_name }}
                            </span>
                    </label>

                {% else %}

                {% endfor %}
                </div>
            {% else %}
            {% endfor %}


            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-8">
                    <button type="submit" class="btn btn-success" data-loading-text="保存中...">确定</button>
                    <button type="button" class="btn btn-default" onclick="window.location=window.document.referrer;">返回</button>
                </div>
            </div>
        </form>
    </div>
{% endblock %}
{% block footer %}
    <script type="text/javascript">
        $(function () {
            $("#formResourceEdit").ajaxForm({
                success : function ($res) {
                    if($res.errCode === 0){
                        $("#resource_id").val($res.data.resource_id)
                        layer.msg('保存成功',{
                            time:1000,
                            icon:1
                        },function () {
                            window.document.location = "{{ url('resource/list') }}"
                        });
                    }else{
                        layer.msg($res.errMsg);
                    }
                }
            });
        });
    </script>
{% endblock %}
